//
//  ZLViewController.m
//  ZLTableView
//
//  Created by Zz_l on 03/19/2022.
//  Copyright (c) 2022 Zz_l. All rights reserved.
//

#import "ZLViewController.h"
#import <ZLTableView/ZLTableView.h>
#import "ZLTestCell.h"
#import "ZLTestNibCell.h"

@interface ZLViewController ()
@property (nonatomic, strong) ZLTableView *table;
@property (nonatomic, strong) UIView *headView;
@end

@implementation ZLViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor yellowColor];
    
    self.table = [[ZLTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    [self.view addSubview:self.table];
    [self.table registerCell:@[@"ZLTestCell"]];
    [self.table registerCellNib:@[@"ZLTestNibCell"]];
    
    [self.table sectionNumber:^NSInteger{
        return 2;
    } rowNumber:^NSInteger(NSInteger section) {
        return 20;
    } cellHeight:^CGFloat(NSIndexPath * _Nonnull indexPath) {
        return 50;
    } indexPathCell:^UITableViewCell * _Nullable(UITableView * _Nonnull tableview, NSIndexPath * _Nonnull indexPath) {
        ZLTestCell *cell = [tableview dequeueReusableCellWithIdentifier:@"ZLTestCell" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor colorWithWhite:0 alpha:0.8];
        return cell;
    }selectCell:^(NSIndexPath * _Nonnull indexPath) {
        
    }];
    [self.table sectionHeaderHeight:^CGFloat(NSInteger section) {
        return 50;
    } sectionHeaderView:^UIView * _Nullable(NSInteger section) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
        view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
        return view;
    }];
    self.table.tableview.tableHeaderView = self.headView;
    [self.table reloadData];
}

- (UIView *)headView {
    if (!_headView) {
        _headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200) ];
        _headView.backgroundColor = [UIColor yellowColor];
    }
    return _headView;
}

@end
